﻿using PmSadis.Models.Abstract;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System;

namespace PmSadis.Models
{
    /// <summary>
    /// Материал
    /// </summary>
    [Table("S_MATERIAL")]
    public class Material : Resource
    {
        /// <summary>
        /// Идентификатор
        /// </summary>
        [Column("MATERIAL_ID")]
        [Key]
        public int MaterialId { get; set; }
    }

    /// <summary>
    /// Материал в справочной работе
    /// </summary>
    [Table("S_WORK_MATERIAL")]
    public class WorkMaterial : IRedactModel
    {
        /// <summary>
        /// Идентификатор
        /// </summary>
        [Column("WORK_MATERIAL_ID")]
        public int WorkMaterialId { get; set; }

        /// <summary>
        /// Идентификатор материала
        /// </summary>
        [Column("MATERIAL_ID")]
        public int MaterialId { get; set; }
        public virtual Material Material { get; set; }

        /// <summary>
        /// Идентификатор работы
        /// </summary>
        [Column("WORK_ID")]
        public int WorkId { get; set; }
        public virtual Work Work { get; set; }

        /// <summary>
        /// Объем материала
        /// </summary>
        [Column("VALUE")]
        public double Value { get; set; }

        /// <summary>
        /// Дата создания
        /// </summary>
        [Column("DATE_CREATE")]
        public DateTime DateCreate { get; set; }

        /// <summary>
        /// Дата редактирования
        /// </summary>
        [Column("DATE_UPDATE")]
        public DateTime DateUpdate { get; set; }

        [NotMapped]
        public string Name
        {
            get
            {
                return this.Material.Name;
            }
        }
        [NotMapped]
        public int? UnitId
        {
            get
            {
                return this.Material.UnitId;
            }
        }
        [NotMapped]
        public decimal CostBase
        {
            get
            {
                return this.Material.CostBase;
            }
        }
        [NotMapped]
        public decimal Cost
        {
            get
            {
                return this.CostBase*(decimal)this.Value;
            }
        }
    }
}
